package com.yonder.controller;

import com.yonder.common.MessageConstant;
import com.yonder.entity.Result;
import com.yonder.service.OrderSettingService;
import com.yonder.utils.POIUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName OrderSettingController
 * @Description TODO
 * @Author zxs
 * @Date 2021/3/21 21:02
 * Version 1.0
 */

@RestController
@RequestMapping("/ordersetting")

public class OrderSettingController {

    @Autowired
    private OrderSettingService orderSettingService;

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public Result addOrderSet(MultipartFile excelFile) {

        /*http://localhost:8888/ordersetting/upload.do
         * 对前端发送的excelFile文件先进行解析，使用POI类进行处理
         * */
        List<String[]> excelStrings = null;
        try {
            excelStrings = POIUtils.readExcel(excelFile);
            orderSettingService.add(excelStrings);
            return new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(true, MessageConstant.IMPORT_ORDERSETTING_FAIL);
    }
}
